home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
Add-Ons
/
After Dark
/
Twist 1.0b1
/
ADTestbed.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-06-29
|
11KB
|
565 lines
/* ADTestbed.c
* Test bed to allow source code debugging of After Dark modules.
* Copyright ©1996 Michael D. Crawford. All Rights Reserved.
* You may use this code on the condition that you read the following web page:
* http://www.scruznet.com/~crawford/WordServices/wdsvindex.html
*/
#include "GraphicsModule_Types.h"
#include "ADTestbed.h"
typedef struct {
GMParamBlockPtr paramPtr;
Handle storage;
Boolean running;
RgnHandle blankRgn;
} tTBRec, *tTBPtr;
void InitManagers( void );
void EventLoop( void );
void DoMouseDown( EventRecord *evtPtr );
void DoKeyDown( EventRecord *evtPtr );
void PutUpMenus( void );
void DoMenuCommand( long theLong );
void DoAppleMenu( short theItem );
void DoFileMenu( short theItem );
void DoEditMenu( short theItem );
void DoTestbedMenu( short theItem );
void DoNewWindow( void );
void RequestQuit( void );
void DoUpdate( WindowPtr win );
void DoCloseWindow( void );
tTBPtr NewTBRec( GrafPtr port, Rect *globalBoundsPtr, Rect *localBoundsPtr );
void SendMessage( WindowPtr docWindow, short message );
void DoIdleEvent( void );
void FixMenuMarks( void );
#define kMBarID 128
enum{
kAppleMenuID = 128,
kFileMenuID,
kEditMenuID,
kTestbedMenuID
};
enum{
kAMAbout = 1,
kAMDash1
};
enum{
kFMNew = 1,
kFMClose,
kFMDash1,
kFMQuit
};
enum{
kEMUndo = 1,
kEMDash1,
kEMCut,
kEMCopy,
kEMPaste
};
enum{
kTMInitialize = 1,
kTMBlank,
kTMDrawframe,
kTMClose,
kTMButtonMessage,
kTMModuleSelected,
kTMDoHelp,
kTMDash1,
kTMRun
};
static Boolean gQuitRequested;
static WindowPtr gDocWindow;
void main( void )
{
InitManagers();
gQuitRequested = false;
PutUpMenus();
EventLoop();
ExitToShell();
}
void EventLoop( void )
{
EventRecord evt;
do{
WaitNextEvent( everyEvent, &evt, 1, (RgnHandle)NULL );
switch ( evt.what ){
case nullEvent:
DoIdleEvent();
break;
case mouseDown:
DoMouseDown( &evt );
break;
case mouseUp:
break;
case keyDown:
DoKeyDown( &evt );
break;
case keyUp:
break;
case autoKey:
break;
case updateEvt:
DoUpdate( (WindowPtr)evt.message );
break;
case diskEvt:
break;
case activateEvt:
break;
case osEvt:
break;
}
}while ( !gQuitRequested );
return;
}
void DoAppleMenu( short theItem )
{
return;
}
void DoFileMenu( short theItem )
{
switch( theItem ){
case kFMNew:
DoNewWindow();
break;
case kFMClose:
DoCloseWindow();
break;
case kFMDash1:
break;
case kFMQuit:
RequestQuit();
break;
}
return;
}
void DoEditMenu( short theItem )
{
return;
}
void DoTestbedMenu( short theItem )
{
switch( theItem ){
case kTMInitialize:
SendMessage( gDocWindow, Initialize );
break;
case kTMBlank:
SendMessage( gDocWindow, Blank );
break;
case kTMDrawframe:
SendMessage( gDocWindow, DrawFrame );
break;
case kTMClose:
SendMessage( gDocWindow, Close );
break;
case kTMButtonMessage:
// STUB get this from a dialog or modeless control panel dialog
SendMessage( gDocWindow, ButtonMessage );
break;
case kTMModuleSelected:
break;
case kTMDoHelp:
SendMessage( gDocWindow, DoAbout );
break;
case kTMDash1:
break;
case kTMRun:
if ( ( (tTBPtr)( (WindowPeek)gDocWindow )->refCon )->running ){
( (tTBPtr)( (WindowPeek)gDocWindow )->refCon )->running = false;
}else{
( (tTBPtr)( (WindowPeek)gDocWindow )->refCon )->running = true;
}
break;
}
return;
}
void DoIdleEvent( void )
{
if ( gDocWindow ){
if ( ( (tTBPtr)( (WindowPeek)gDocWindow )->refCon )->running ){
SendMessage( gDocWindow, DrawFrame );
}
}
return;
}
void SendMessage( WindowPtr docWindow, short message )
{
tTBPtr tbPtr;
OSErr err;
tbPtr = (tTBPtr)( (WindowPeek)docWindow )->refCon;
err = ADEntry( &tbPtr->storage, tbPtr->blankRgn, message, tbPtr->paramPtr );
if ( err ){
DebugStr( "\pGot an error from After Dark module" );
}
return;
}
void DoMenuCommand( long menuSpot )
{
short theMenu;
short theItem;
Boolean result;
theMenu = HiWord( menuSpot );
theItem = LoWord( menuSpot );
switch ( theMenu ){
case 0:
break;
case kAppleMenuID:
DoAppleMenu( theItem );
break;
case kFileMenuID:
DoFileMenu( theItem );
break;
case kEditMenuID:
DoEditMenu( theItem );
break;
case kTestbedMenuID:
DoTestbedMenu( theItem );
break;
}
HiliteMenu( 0 );
return;
}
void DoMouseDown( EventRecord *eventPtr )
{
WindowPtr theWindow;
Rect dragRect;
short deskPart;
deskPart = FindWindow( eventPtr->where, &theWindow );
switch( deskPart ){
case inDesk:
break;
case inMenuBar:
FixMenuMarks();
DoMenuCommand( MenuSelect( eventPtr->where ) );
break;
case inSysWindow:
SystemClick( eventPtr, theWindow );
break;
case inContent:
if ( theWindow != FrontWindow() ){
SelectWindow( theWindow );
} else {
}
break;
case inDrag:
DragWindow( theWindow, eventPtr->where, &qd.screenBits.bounds ); /* NOT correct but works */
break;
case inGrow:
//GrowDocWindow( theWindow, eventPtr->where );
break;
case inGoAway:
if ( TrackGoAway( theWindow, eventPtr->where ))
DoCloseWindow();
break;
case inZoomIn:
case inZoomOut:
//if ( TrackBox( theWindow, eventPtr->where, deskPart ) )
// DoZoom( theWindow, deskPart );
break;
}
return;
}
void DoKeyDown( EventRecord *evtPtr )
{
char theChar;
theChar = evtPtr->message & charCodeMask;
if ( evtPtr->modifiers & cmdKey ){
FixMenuMarks(); /* We need to have the dis/enabling up to date */
DoMenuCommand( MenuKey( theChar ) );
}
return;
}
void FixMenuMarks( void )
{
return;
}
void InitManagers( void )
{
MaxApplZone();
//InitGraf(&thePort);
InitGraf(&qd.thePort);
InitFonts();
/* FlushEvents(everyEvent, 0); */
InitWindows();
TEInit();
InitDialogs(0L);
InitCursor();
return;
}
void PutUpMenus( void )
{
Handle myMenuBar;
MenuHandle appleMenu;
MenuHandle fontMenu;
myMenuBar = GetNewMBar( kMBarID );
if ( !myMenuBar ){
DebugStr( "\pCannot get menu bar" );
return;
}
appleMenu = (MenuHandle)GetResource( 'MENU', kAppleMenuID );
if ( !appleMenu ){
DebugStr( "\pcannot get Apple Menu Handle" );
return;
}
AddResMenu( appleMenu, 'DRVR' );
SetMenuBar( myMenuBar );
DrawMenuBar();
return;
}
void DoNewWindow( void )
{
PicHandle teaParty;
Rect r;
tTBPtr tbPtr;
Point tlPt;
Point brPt;
Rect globalR;
Rect localR;
if ( gDocWindow )
return;
gDocWindow = GetNewWindow( 128, (void*)NULL, (WindowRef)-1 );
if ( !gDocWindow ){
DebugStr( "\pCan't make new window" );
return;
}
teaParty = GetPicture( 128 );
if ( !teaParty ){
DebugStr( "\pNo tea for Michael tonight" );
return;
}
DetachResource( (Handle)teaParty );
r = (*teaParty)->picFrame;
SizeWindow( gDocWindow, r.right - r.left, r.bottom - r.top, true );
( (WindowPeek)gDocWindow )->windowPic = teaParty;
SetPort( gDocWindow );
tlPt.h = 0;
tlPt.v = 0;
brPt.h = r.right - r.left;
brPt.v = r.bottom - r.top;
SetRect( &localR, 0, 0, brPt.h, brPt.v );
LocalToGlobal( &tlPt );
LocalToGlobal( &brPt );
SetRect( &globalR, tlPt.h, tlPt.v, brPt.h, brPt.v );
tbPtr = NewTBRec( gDocWindow, &globalR, &localR );
if ( !tbPtr ){
DebugStr( "\pOutta luck" );
return;
}
( (WindowPeek)gDocWindow )->refCon = (long)tbPtr;
return;
}
tTBPtr NewTBRec( GrafPtr port, Rect *globalBoundsPtr, Rect *localBoundsPtr )
{
tTBPtr tbPtr;
GMParamBlockPtr paramPtr;
short i;
MonitorsInfoPtr monitors;
AD_QDGlobalsPtr qdGlobalsCopy;
StringPtr errorMessage;
SndChannelPtr sndChannel;
RgnHandle blankRgn;
paramPtr = (GMParamBlockPtr)NewPtr( sizeof( GMParamBlock ) );
if ( !paramPtr )
return (tTBPtr)NULL;
tbPtr = (tTBPtr)NewPtr( sizeof( tTBRec ) );
if ( !tbPtr )
return (tTBPtr)NULL;
tbPtr->paramPtr = paramPtr;
tbPtr->storage = (Handle)NULL;
tbPtr->running = false;
blankRgn = NewRgn();
if ( !blankRgn ){
return (tTBPtr)NULL;
}
RectRgn( blankRgn, localBoundsPtr );
tbPtr->blankRgn = blankRgn;
for ( i = 0; i < 4; i++ )
paramPtr->controlValues[ i ] = 0;
monitors = (MonitorsInfoPtr)NewPtr( sizeof( MonitorsInfo ) );
monitors->monitorCount = 1;
monitors->monitorList[ 0 ].bounds = *globalBoundsPtr;
monitors->monitorList[ 0 ].synchFlag = true; // STUB use a slot VBL
monitors->monitorList[ 0 ].curDepth = 8; // STUB get it from monitor
paramPtr->monitors = monitors;
paramPtr->colorQDAvail = true;
/* 0xc2ff
1111
Bit 0: cqdAvail - The Macintosh has Color QuickDraw.
Bit 1: anyMultibit - A monitor is set to greater than 1 bit in depth.
Bit 2: allMultibit - All monitors are set to greater than 1 bit in depth.
Bit 3: anyColor - A monitor is in color mode.
1111
Bit 4: allColor - All monitors are in color mode.
Bit 5: anyCLUTDevice - A monitor is a CLUT device.
Bit 6: allCLUTDevice - All monitors are CLUT devices.
Bit 7: allCanDim - All monitors can dim.
0010
Bit 8: mainMonCanDim - The main monitor can dim.
Bit 9: moduleMayNotAnimate - Module may not animate the color table.
Bit 10: multiModuleRunning - Module is running under MultiModule.
Bits 11-13: Reserved.
0100
Bit 14: extensionsAvailable - Module is running under After Dark 2.0u or later.
Bit 15: soundAvail - This version of After Dark supports sound.
*/
#define kMikesConfig 0x42ff
paramPtr->systemConfig = kMikesConfig;
qdGlobalsCopy = (AD_QDGlobalsPtr)NewPtr( sizeof( AD_QDGlobals ) );
if ( !qdGlobalsCopy )
return (tTBPtr)NULL;
qdGlobalsCopy->qdThePort = qd.thePort;
qdGlobalsCopy->qdWhite = qd.white;
qdGlobalsCopy->qdBlack = qd.black;
qdGlobalsCopy->qdGray = qd.gray;
qdGlobalsCopy->qdLtGray = qd.ltGray;
qdGlobalsCopy->qdDkGray = qd.dkGray;
qdGlobalsCopy->qdArrow = qd.arrow;
qdGlobalsCopy->qdScreenBits = qd.screenBits;
qdGlobalsCopy->qdRandSeed = qd.randSeed;
paramPtr->qdGlobalsCopy = qdGlobalsCopy;
paramPtr->brightness = 255;
SetRect( ¶mPtr->demoRect, 0, 0, 0, 0 );
errorMessage = (StringPtr)NewPtr( sizeof( Str255 ) );
paramPtr->errorMessage = errorMessage;
sndChannel = (SndChannelPtr)NULL;
paramPtr->sndChannel = sndChannel;
paramPtr->adVersion = 0x0300;
paramPtr->extensions = (ExtensionTablePtr)NULL;
return tbPtr;
}
void DoCloseWindow( void )
{
PicHandle teaParty;
if ( !gDocWindow )
return;
teaParty = ( (WindowPeek)gDocWindow )->windowPic;
if ( teaParty ){
KillPicture( teaParty );
}
// STUB dispose of tTBRec and its fields
DisposeWindow( gDocWindow );
gDocWindow = (WindowRef)NULL;
return;
}
void RequestQuit( void )
{
gQuitRequested = true;
return;
}
void DoUpdate( WindowPtr win )
{
GrafPtr oldPort;
Rect r;
BeginUpdate( win );
r = ( *( (WindowPeek)win )->windowPic)->picFrame;
GetPort( &oldPort );
SetPort( win );
DrawPicture( ( (WindowPeek)win )->windowPic, &r );
SetPort( oldPort );
EndUpdate( win );
return;
}